package com.dmall.promotion.service;

import com.alibaba.fastjson.JSON;
import com.dmall.promotion.annotation.UserOperation;
import com.dmall.promotion.domain.User;
import com.dmall.promotion.enums.UserOperationEnum;
import com.dmall.promotion.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户操作Service
 * @author xiao1.wang
 * @date 2021-06-03 17:41:40
 */
@Service
@Slf4j
public class UserService {

    @Resource
    private UserMapper userMapper;

    public User get(Integer id) {
        log.info("UserService get id={}", id);
        return userMapper.select(id);
    }

    @UserOperation(UserOperationEnum.ADD)
    public void add(User user) {
        log.info("UserService save user={}", JSON.toJSONString(user));
        userMapper.insert(user);
    }

    @UserOperation(UserOperationEnum.MODIFY)
    public void modify(User user) {
        log.info("UserService modify user={}", JSON.toJSONString(user));
        userMapper.insert(user);
    }

    @UserOperation(UserOperationEnum.DELETE)
    public void delete(Integer id) {
        log.info("UserService delete id={}", id);
        userMapper.delete(id);
    }

    public List<User> userList() {
        log.info("UserService userList");
        return userMapper.selectAll();
    }
}
